//
//  FSEmoticonPackageModel.m
//  FSWeiBo(Objc)
//
//  Created by lyw on 15/9/17.
//  Copyright (c) 2015年 cn.liuyawei. All rights reserved.
//

#import "FSEmoticonPackageModel.h"
#import "FSEmoticonModel.h"


@implementation FSEmoticonPackageModel

+ (instancetype)emoticonPackageModelWithDict:(NSDictionary*)dict
{

    FSEmoticonPackageModel* model = [[FSEmoticonPackageModel alloc] init];
    if (!dict) {
        model.emoticons = [NSMutableArray array];
        return [model addEmptyButton];
    }
    model.id = dict[@"id"];
    model.group_name_cn = dict[@"group_name_cn"];
    NSMutableArray* arrayM = [NSMutableArray array];
    NSArray* array = dict[@"emoticons"];
    int indexPath = 0;
    for (NSDictionary* dict in array) {
        FSEmoticonModel* emodel = [FSEmoticonModel emoticonModelWithDict:dict];
        emodel.id = model.id;
        if (indexPath == 20) {
            FSEmoticonModel* deleteEm = [[FSEmoticonModel alloc] init];
            deleteEm.isDeleteButton = YES;
            [arrayM addObject:deleteEm];
            indexPath = 0;
        }
        indexPath++;
        [arrayM addObject:emodel];
    }
    model.emoticons = arrayM;

    return [model addEmptyButton];
}
- (FSEmoticonPackageModel*)addEmptyButton
{
    if (self.emoticons.count % 21 != 0 || self.emoticons.count == 0) {
        NSUInteger count = 20 - self.emoticons.count % 21;
        for (NSUInteger i = 0; i < count; i++) {
            FSEmoticonModel* emodel = [[FSEmoticonModel alloc] init];
            emodel.isEmptyButton = YES;
            [self.emoticons addObject:emodel];
        }
        FSEmoticonModel* delete = [[FSEmoticonModel alloc] init];
        delete.isDeleteButton = YES;
        [self.emoticons addObject:delete];
    }
    return self;
}


-(void)setValue:(id)value forUndefinedKey:(NSString *)key{

}

@end
